<?php
namespace Infinity;

abstract class Message {
  public static function remove($message, $operator = '==', $type = 'status'){
    drupal_session_start();
    if(isset($_SESSION['messages'][$type])) {
      foreach($_SESSION['messages'][$type] as $key => $m) {
        if($operator == '==' && $m == $message) {
          unset($_SESSION['messages'][$type][$key]);
        }
        if($operator == 'CONTAINS' && String::contains($m, $message)) {
          unset($_SESSION['messages'][$type][$key]);
        }
        if($operator == 'STARTS_WITH' && String::startsWith($m, $message)) {
          unset($_SESSION['messages'][$type][$key]);
        }
        if($operator == 'ENDS_WITH' && String::endsWith($m, $message)) {
          unset($_SESSION['messages'][$type][$key]);
        }
      }
      if(count($_SESSION['messages'][$type]) == 0)
        unset($_SESSION['messages'][$type]);
      if(count($_SESSION['messages']) == 0)
        unset($_SESSION['messages']);
    }
  }
}